package com.chinasoft.cr.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinasoft.cr.mapper.ReportDataMapper;
import com.chinasoft.cr.pojo.ReportData;
import com.chinasoft.cr.pojo.Result;
import com.chinasoft.cr.pojo.vo.DayCount;
import com.chinasoft.cr.pojo.vo.HomeInfo;
import com.chinasoft.cr.pojo.vo.StatusCount;
import com.chinasoft.cr.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 报告数据管理前端控制器
 * </p>
 *
 * @author pp
 * @since 2025-01-18
 */
@RestController
@CrossOrigin  // 解决跨域问题
@RequestMapping("/api/reportData")
@Tag(name = "报告数据管理", description = "用于管理报告数据信息")
public class ReportDataController {

    @Autowired
    private ReportDataService reportDataService;
    @Autowired
    private ReportDataMapper reportDataMapper;






    /**
     * 分页查询报告数据列表
     *
     * @param current  当前页码
     * @param pageSize 每页大小
     * @return 分页查询结果
     */
//    @GetMapping(value = "/list")
//    @Operation(summary = "分页获取所有报告数据信息", description = "分页查询所有报告数据的详细信息")
//    @ApiResponse(responseCode = "200", description = "分页获取所有报告数据信息成功")
//    public Result list(@RequestParam(required = false) Integer current, @RequestParam(required = false) Integer pageSize,
//                       @RequestParam(required = false) String nickName,@RequestParam(required = false) String venueName) {
//        if (current == null) {
//            current = 1;
//        }
//        if (pageSize == null) {
//            pageSize = 10;
//        }
//
//
//        //Page<ReportData> aPage = reportDataService.page(new Page<>(current, pageSize));
//        Page<ReportData> aPage = reportDataMapper.selectPageVo(new Page<>(current, pageSize),nickName,venueName);
//        System.out.println(aPage);
//        return new Result(200, "查询成功！", aPage);
//    }

    @GetMapping(value = "/getHomeInfo")
    @Operation(summary = "首页信息", description = "首页信息")
    @ApiResponse(responseCode = "200", description = "获取信息成功")
    public Result getHomeInfo() {
        HomeInfo homeInfo = new HomeInfo();
        int venueNumber = reportDataMapper.getVenueNumber();
        homeInfo.setVenueNumber(venueNumber);
        int userNumber = reportDataMapper.getUserNumber();
        homeInfo.setUserNumber(userNumber);
        int reservationNumber = reportDataMapper.getReservationNumber();
        homeInfo.setReservationNumber(reservationNumber);
        int successNumber = reportDataMapper.getReservationSuccessNumber();
        homeInfo.setSuccessNumber(successNumber);

        List<DayCount> everyDayReservation = reportDataMapper.getEveryDayReservation();
        homeInfo.setEveryDayReservation(everyDayReservation);

        List<StatusCount> statusCount = reportDataMapper.getStatusCount();
        homeInfo.setStatusCount(statusCount);
        return new Result(200, "查询成功！",homeInfo);
    };

    /**
     * 根据ID获取报告数据详情
     *
     * @param id 报告数据ID
     * @return 报告数据详情
     */
//    @GetMapping(value = "/{id}")
//    @Operation(summary = "根据报告数据ID获取报告数据信息", description = "根据报告数据ID查询报告数据的详细信息")
//    @ApiResponse(responseCode = "200", description = "获取报告数据信息成功")
//    @ApiResponse(responseCode = "404", description = "获取报告数据信息失败,该报告数据不存在")
//    public Result getById(@PathVariable("id") String id) {
//        ReportData reportData = reportDataService.getById(id);
//        if (reportData == null) {
//            return new Result(404, "报告数据不存在！", null);
//        }
//        return new Result(200, "查询成功！", reportData);
//    }

    /**
     * 创建报告数据
     *
     * @param params 报告数据信息
     * @return 创建结果
     */
//    @PostMapping(value = "/create")
//    @Operation(summary = "创建报告数据", description = "根据提供的报告数据信息创建新报告数据")
//    @ApiResponse(responseCode = "200", description = "报告数据创建成功")
//    @ApiResponse(responseCode = "500", description = "报告数据创建失败,系统错误")
//    public Result create(@RequestBody ReportData params) {
//        try {
//            boolean flag = reportDataService.save(params);
//            if (!flag) {
//                return new Result(500, "创建失败，未知错误！", null);
//            }
//            return new Result(200, "创建成功！", null);
//        } catch (Exception e) {
//            return new Result(500, "创建失败，系统错误：" + e.getMessage(), null);
//        }
//    }

    /**
     * 删除报告数据
     *
     * @param id 报告数据ID
     * @return 删除结果
     */
//    @DeleteMapping(value = "/delete/{id}")
//    @Operation(summary = "删除报告数据", description = "根据报告数据ID删除报告数据")
//    @ApiResponse(responseCode = "200", description = "报告数据删除成功")
//    @ApiResponse(responseCode = "404", description = "删除报告数据失败,该报告数据不存在")
//    public Result delete(@PathVariable("id") String id) {
//        try {
//            boolean flag = reportDataService.removeById(id);
//            if (flag) {
//                return new Result(200, "删除成功！", null);
//            } else {
//                return new Result(404, "删除失败，报告数据不存在！", null);
//            }
//        } catch (Exception e) {
//            return new Result(500, "删除失败，系统错误：" + e.getMessage(), null);
//        }
//    }

    /**
     * 更新报告数据
     *
     * @param params 报告数据信息
     * @return 更新结果
     */
//    @PutMapping(value = "/update")
//    @Operation(summary = "更新报告数据", description = "根据提供的报告数据信息更新现有报告数据")
//    @ApiResponse(responseCode = "200", description = "报告数据更新成功")
//    @ApiResponse(responseCode = "404", description = "报告数据更新失败,该报告数据不存在")
//    public Result update(@RequestBody ReportData params) {
//        try {
//            boolean flag = reportDataService.updateById(params);
//            if (flag) {
//                return new Result(200, "更新成功！", null);
//            } else {
//                return new Result(404, "更新失败，报告数据不存在！", null);
//            }
//        } catch (Exception e) {
//            return new Result(500, "更新失败，系统错误：" + e.getMessage(), null);
//        }
//    }
    //场馆名查询信息接口

    //场馆名查询信息接口

    /**
     * 根据场馆名称模糊查询报告数据
     *
     * @param name     场馆名称
     * @param current  当前页码
     * @param pageSize 每页大小
     * @return 查询结果
     */
//    @GetMapping(value = "/search")
//    @Operation(summary = "根据场馆名称模糊查询报告数据", description = "根据场馆名称模糊查询报告数据的详细信息")
//    @ApiResponse(responseCode = "200", description = "查询成功")
//    public Result searchByVenueName(@RequestParam(required = false) String name,
//                                    @RequestParam(required = false) Integer current,
//                                    @RequestParam(required = false) Integer pageSize) {
//        if (current == null) {
//            current = 1;
//        }
//        if (pageSize == null) {
//            pageSize = 10;
//        }
//
//        LambdaQueryWrapper<ReportData> queryWrapper = new LambdaQueryWrapper<>();
//        if (StringUtils.hasText(name)) {
//            queryWrapper.like(ReportData::getName, name);
//        }
//
//        Page<ReportData> page = reportDataMapper.selectPage(new Page<>(current, pageSize), queryWrapper);
//
//        return new Result(200, "查询成功！", page);
//    }
}